//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#include "general.h"

std::pair<CBBBranch*,std::string> CVirtualBranch::FindBranch(const std::string &pPath,std::size_t pOffset)
{
    std::size_t lComponent=pPath.find('/',pOffset);

    TChildrenMap::iterator lMatch=mChildren.find(pPath.substr(pOffset,lComponent-pOffset));

    if(lMatch==mChildren.end())
        return std::pair<CBBBranch*,std::string>((CBBBranch*)nullptr,"");

    if(lComponent==std::string::npos)
        return std::make_pair(lMatch->second,"");

    return lMatch->second->FindBranch(pPath,lComponent+1);
}

bool CVirtualBranch::GetLeafList(const std::string& /*pPath*/, std::vector<std::string> &pList)
{
    ///\todo investigate why pPath is not used
    for(TChildrenMap::iterator lIt=mChildren.begin();lIt!=mChildren.end();++lIt)
        pList.push_back(lIt->first);

    return true;
}

void CVirtualBranch::AddBranch(const std::string &pName,CBBBranch *pBranch)
{
    mChildren[pName]=pBranch;
}
